#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "OneWire.h"
#include "DS18B20.h"

//char ack;
float T;	//全局变量

void main()
{
	DS18B20_ConvertT();	//先转换1次，
	Delay(1000);		//再延时1s，就不会显示默认温度25了
	
	LCD_Init();
//	LCD_ShowString(1,1,"Temperature:");
//	ack = OneWire_Init();
//	LCD_ShowNum(2,1,ack,3);
	LCD_ShowChar(2,9,0xDF);
	LCD_ShowChar(2,10,'C');
	while(1)
	{		
		DS18B20_ConvertT();
		T = DS18B20_ReadT();
		
		if(T<0)
		{
			LCD_ShowChar(2,1,'-');//显示个负号
			T=-T;	//转化成正数
		}
		else {LCD_ShowChar(2,1,'+');}
		
		LCD_ShowNum(2,2,T,3);//整数部分
		LCD_ShowChar(2,5,'.');
		LCD_ShowNum(2,6,(unsigned long)(T*10000)%10000,3);
		//乘一万，小数部分移动到整数部分，再取余，再强制类型转换unsigned long
		
	}
	
}